<template>
  <div class="app-container">
    <el-row :gutter="32" type="flex" style="margin-bottom:18px;">
      <el-col :xs="24" :sm="24" :lg="8">
        编号
        <el-input
          placeholder="请输入编号"
          prefix-icon="el-icon-search"
          style="width:180px"
        />

      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        名称
        <el-input
          placeholder="请输入名称"
          prefix-icon="el-icon-search"
          style="width:180px"
        />

      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        型号
        <el-input
          placeholder="请输入型号"
          prefix-icon="el-icon-search"
          style="width:180px"
        />

      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <el-button type="primary" @click="search">搜索</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      fit
      border
      highlight-current-row
      page
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column align="center" label="编号" width="95">
        <template slot-scope="scope">
          {{ scope.row.lid }}
        </template>
      </el-table-column>
      <el-table-column label="图片" width="120">
        <template slot-scope="scope">
          <img :src="require(`@/assets/${scope.row.pic}`)" alt="" style="width:90px;">
        </template>
      </el-table-column>
      <el-table-column label="型号" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.fname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主标题" align="center">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column
        class-name="status-col"
        label="规格"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.spec }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="created_at"
        label="单价"
        width="200"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <el-button>详情</el-button>
        <el-button>修改</el-button>
      </el-table-column>
    </el-table>
    <el-row style="margin-top:18px;">
      <el-pagination
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>

  </div>
</template>

<script>
import { queryList } from '@/api/table'

export default {
  data() {
    return {
      list: [],
      listLoading: true,
      page: 0,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      const { page, pageSize } = this
      queryList({
        pno: page,
        pageSize
      }).then((response) => {
        const { data, recordCount } = response
        this.list = data
        this.total = recordCount
        this.listLoading = false
      })
    },
    handleSelectionChange(selection) {
      console.log(selection)
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.fetchData()
    },
    handleCurrentChange(page) {
      this.page = page
      this.fetchData()
    },
    search() {}
  }
}
</script>
